<?php
class Admin_SystemAccessController extends Zend_Controller_Action
{       
    public function accessManagerAction()
    {
    	$viewmode = $this->_getParam('viewmode','all');
    	$urlUpdate = $this->view->url( array( 	'language'	=> zend_registry::get('Zend_Locale'),
    											'module'	=> 'admin',
    											'controller'=> 'system-access',
    											'action'	=> 'access-manager'	) );
    	
    	switch($viewmode) {
    		case 'byaction'	: 
    			$actionid = $this->_getParam('actid');    			
    			
    			//update roles access if form post is requested
    			$updateAccess = new RolesManagerByActionUpdate($actionid,$this->view,$this->getRequest());
    			
    			//get a form with roles access 
    			$rolesManager = new RolesManagerByAction($actionid,$urlUpdate);    			
				$this->view->data = $rolesManager->getData();
    				break;
    				
    		default	: 
    			//get the given role name
    			$rolename = $this->_getParam('role');
    			
    			$filterBymodule = $this->_getParam('modname','all');
    			    			
    			//update roles access if form post is requested
    			$rolesManager = new RolesManagerByRole($rolename,$filterBymodule,$this->getRequest());
    			$this->view->data = $rolesManager->getData();    			 
    			break;
    	}    	
    	    	
    }
        
	public function actionAccessAction()
    {
    	if(!$this->_hasParam('actid')) 
    		return ; 
    	$actionid = $this->_getParam('actid');
    	$currentAction = new Wmp_Model_ActionparamsTable();
    	$currentAction = $currentAction->getAction($actionid);
    	
    	$aclRights = new Wmp_Model_AclrightsTable();    	
    	
    	$data = array();
    	$data['roles'] = $aclRights->getRolesByAction($actionid);  
    	$data['action'] = $currentAction;
    	$this->view->data = $data;  		 
    }
    
    public function moduleAccessAction()
    {
    	if(!$this->_hasParam('modname'))
    		return;
    			
    	$modulename = $this->_getParam("modname");
    	
    	$moduleactions = new Wmp_Model_ActionparamsTable();
    	$moduleactions = $moduleactions->getActions($modulename);
    	
    	$aclRights = new Wmp_Model_AclrightsTable();
    	
    	$alldata=array();    	
    	
    	foreach($moduleactions as $currentaction) {
    		$data = array();
    		$data['roles'] = $aclRights->getRolesByAction($currentaction->id);  
    		$data['action'] = $currentaction;
    		$alldata[]=$data;
    	}	
    	
    	$this->view->alldata = $alldata;
    }
}